package services

import (
	"context"
	"github.com/cloudwego/hertz/pkg/common/hlog"
	"mall_frontend_api/biz/dal"
	"mall_frontend_api/biz/handler/base"
	"mall_frontend_api/biz/model"
	"mall_frontend_api/biz/model/common"
	"mall_frontend_api/biz/model/user_report"
)

type UserReportService struct {
	ctx    context.Context
	common *base.Response
	dao    *dal.InitDAO
}

func NewUserReportService(ctx context.Context, common *base.Response) *UserReportService {
	return &UserReportService{ctx: ctx, common: common, dao: dal.NewInitDAO()}
}

func (c *UserReportService) Create(req *user_report.CreateUserReportRequest) error {
	var data model.UserReport
	data.Email = req.Email
	data.Report = req.Report
	data.Mobile = req.Mobile
	data.Type = req.Type
	data.Status = common.UserReportStatus_Submit
	data.Name = req.Name
	data.BizID = c.common.GetBizID()
	if _, err := c.dao.UserReportDAO.Create(c.ctx, &data); err != nil {
		hlog.CtxErrorf(c.ctx, "dao.UserReportDAO.Create() error: %v", err)
		return err
	}
	return nil
}
